import pandas as pd
import numpy as np

import fileUtil
from 每日工作 import run
from 每日工作.InputFile import Input


def invoke():
    data = pd.read_excel(Input.incident_Worksheet)  # type: pd.DataFrame
    data = run.filter_company(data, '完成处理组')
    # 筛选时间
    data['建单时间'] = pd.to_datetime(data['建单时间'])
    date = pd.Timestamp(Input.startTime)
    data = data.loc[data['建单时间'] >= date]
    date = pd.Timestamp(Input.endTime)
    data = data.loc[data['建单时间'] <= date]
    sheet2 = data
    # 筛选指定列
    data = data[
        ['工单名称', '完成处理组', '机房名称（接口传递）', 'T2阶段处理措施', '故障历时', '网元名称', '保障场景',
         '根因分类']]

    # 插入三列
    data.insert(5, '是否需调研', np.nan)
    data.insert(5, '跟踪结论', np.nan)
    data.insert(5, '是否跟踪', np.nan)
    current_date = Input.datetime
    path = f"/家宽/中断投诉跟踪表/中断投诉跟踪表{current_date}/1、故障工单结论表{current_date}.xlsx"
    fileUtil.mkdir(path)

    with pd.ExcelWriter(path, engine='xlsxwriter') as writer:
        data.to_excel(writer, sheet_name='Sheet1', index=False)
        sheet2.to_excel(writer, sheet_name='明细', index=False)

        # 获取工作簿和工作表对象
        workbook = writer.book
        worksheet = writer.sheets['Sheet1']

        # 设置要高亮的列（第6-8列，索引从0开始）
        highlight_format = workbook.add_format({'bg_color': 'yellow'})
        worksheet.set_column(5, 7, None, highlight_format)  # 第6-8列设置黄色背景

        # 设置第1-5列的宽度为20
        worksheet.set_column(0, 4, 20)
